#include <stdio.h>
#define  M   40
#define  N   11
int Mean(int answer[], int n);
int Median(int answer[], int n);
int Mode(int answer[], int n);
void DataSort(int a[], int n);
int main()
{	   		 		     
    int  i, feedback[M]; //1
    printf("Input the feedbacks of 40 students:\n"); //1
    for (i = 0; i < M; i++) //1
    {	   		 		     
        scanf("%d", &feedback[i]); //1
    }
    printf("Mean value = %d\n", Mean(feedback, M)); //1
    printf("Median value = %d\n", Median(feedback, M)); //1
    printf("Mode value = %d\n", Mode(feedback, M)); //1
    return 0;
}	   		 		     
/* 函数功能：若n>0则计算并返回n个数的平均数，否则返回-1 */
int Mean(int answer[], int n)
{	   		 		     
    int i, sum = 0;  //1
    for (i = 0; i < n; i++) //1
    {	   		 		     
        sum += answer[i];//1
    }
    return  n > 0 ? sum / n : -1;
}	   		 		     
/* 函数功能：计算n个数的中位数 */
int Median(int answer[], int n)
{	   		 		     
    DataSort(answer, n); //1
    if (n % 2 == 0) //1
        return  (answer[n / 2] + answer[n / 2 - 1]) / 2;
    else
        return  answer[n / 2];
}	   		 		     
/* 函数功能：计算n个数的众数 */
int Mode(int answer[], int n)
{	   		 		     
    int  i, grade, max = 0, modeValue = 0, count[N] = {0};//1
    for (i = 0; i < n; i++)
    {	   		 		     
        count[answer[i]]++;//1
    }
    for (grade = 1; grade <= N - 1; grade++)//1
    {	   		 		     
        if (count[grade] > max)//1
        {	   		 		     
            max = count[grade];//1
            modeValue = grade;
        }
    }
    return modeValue;
}	   		 		     
/*  函数功能：按选择法对数组a中的n个元素进行排序 */
void DataSort(int a[], int n)
{	   		 		     
    int i, j, k, temp;//1
    for (i = 0; i < n - 1; i++)//1
    {	   		 		     
        k = i;//1
        for (j = i + 1; j < n; j++)//1
        {	   		 		     
            if (a[j] > a[k]) k = j;//1
        }
        if (k != i)//1
        {	   		 		     
            temp = a[k];//1
            a[k] = a[i];//1
            a[i] = temp;//1
        }
    }
}